$(".loginBtn").click(function() {
    getLog()
   })
   
   function getLog() {
    $.ajax({
     url: "http://127.0.0.1/kv/usermsg.php",
     type: "POST",
     data: {
      userName: $("#uName").val(),
      userPswd: $("#uPwd").val(),
     },
     success: function(res) {
      // debugger
      console.log(res);
      if (res == "success") {
       alert("登录成功");
      //  let res = {
      //   userName: 'qqq',
      //   id: '1'
      //  }
      //  window.location.href = 'http://127.0.0.1/teapot/html/first.html';
      //  localStorage.setItem('login', JSON.stringify(res));
      } else {
       alert('账号密码错误或不存在');
      }
     }
    })
   }
$('.regBtn').click(function() {
      getReg()
     })
     
     function getReg() {
      $.ajax({
       url: "http://127.0.0.1/kv/register.php",
       type: "post",
       data: {
        userName: $("#uName").val(),
        userPswd: $("#uPwd").val(),
       },
       success: function(account) {
        // debugger
        console.log(account);
        if (account == 1) {
         alert("账号已注册");
        } else {
         alert("注册成功 去登录");
         // window.location.href = 'http://127.0.0.1/teapot/html/signIn.html';
        }
     
       }
      })
     }

// 页面渲染
   $.ajax({
    url: "./kv.php",
    dataType: "json",
    success(data) {
     console.log(data)
     data.forEach(Element => {
      let item = `
         <li>
         <span>${Element.goodsName}</span>
         <img src="${Element.goodsImg}">
         </li>
      `
      $(".main1-ul").append(item);
     })
    }
   })